//
//  BKZhuanYeViewModel.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/6.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKZhuanYeViewModel.h"
#import <AFNetworking.h>

@implementation BKZhuanYeViewModel

- (id)init{

    self = [super init];
    if (self) {
        _benke = @{@"哲学":@"01",
            @"经济学":@"02",
            @"法学":@"03",
            @"教育学":@"04",
            @"文学":@"05",
            @"历史学":@"06",
            @"理学":@"07",
            @"工学":@"08",
            @"农学":@"09",
            @"医学":@"10",
            @"管理学":@"12",
            @"艺术学":@"13"};
        
        _zhuanke = @{@"农林牧渔大类":@"51",
                     @"交通运输大类":@"52",
                     @"生化与药品大类":@"53",
                     @"资源开发与测绘大类":@"54",
                     @"材料与能源大类":@"55",
                     @"土建大类":@"56",
                     @"水利大类":@"57",
                     @"制造大类":@"58",
                     @"电子信息大类":@"59",
                     @"环保、气象与安全大类":@"60",
                     @"轻纺食品大类":@"61",
                     @"财经大类":@"62",
                     @"医药卫生大类":@"63",
                     @"旅游大类":@"64",
                     @"公共事业大类":@"65",
                     @"文化教育大类":@"66",
                     @"艺术设计与传媒大类":@"67",
                     @"公安大类":@"68",
                     @"法律大类":@"69"};
        
;
;
        
        
    }
    return self;
}


- (void)benkeWithType:(NSString *)type success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure{

    
    NSDictionary *params = @{@"type":_benke[type]};
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/index/getben"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *dataArray = responseDic[@"extraData"];
                 
                 NSMutableArray *array = [NSMutableArray array];
                 for (NSDictionary *dic in dataArray) {
                     if ([dic isKindOfClass:[NSDictionary class]]) {
                         if ([dic[@"major"] isKindOfClass:[NSArray class]]) {
                             [array addObjectsFromArray:dic[@"major"]];
                             
                             
                         }
                     }
                 }
                 
                 [array addObjectsFromArray:dataArray];
                 success(array);
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
    

    
}

-(void)zhuankeWithType:(NSString *)type success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure{

    NSDictionary *params = @{@"type":_zhuanke[type]};
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/index/getzhuan"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *dataArray = responseDic[@"extraData"];
                 
                 NSMutableArray *array = [NSMutableArray array];
                 for (NSDictionary *dic in dataArray) {
                     if ([dic isKindOfClass:[NSDictionary class]]) {
                         if ([dic[@"major"] isKindOfClass:[NSArray class]]) {
                             [array addObjectsFromArray:dic[@"major"]];
                             
                             
                         }
                     }
                 }
                 
                 [array addObjectsFromArray:dataArray];
                 success(array);
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];

    
}
+ (void)colleageWithKaoqu:(NSString *)kaoqu wenli:(NSString *)wenli piciCode:(NSString *)pici dalei:(NSString *)dalei zhuanye:(NSString *)zhuanye page:(NSString *)page success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (kaoqu !=nil) {
        
        NSDictionary *dic = @{@"不限":@"",
                              @"北京":@"1",
                               @"天津":@"2",
                               @"上海":@"3",
                               @"重庆":@"4",
                               @"河北":@"5",
                               @"河南":@"6",
                               @"山东":@"7",
                               @"山西":@"8",
                               @"安徽":@"9",
                               @"江西":@"10",
                               @"江苏":@"11",
                               @"浙江":@"12",
                               @"湖北":@"13",
                               @"湖南":@"14",
                               @"广东":@"15",
                               @"广西":@"16",
                               @"云南":@"17",
                               @"贵州":@"18",
                               @"四川":@"19",
                               @"陕西":@"20",
                               @"青海":@"21",
                               @"宁夏":@"22",
                               @"黑龙江":@"23",
                               @"吉林":@"24",
                               @"辽宁":@"25",
                               @"西藏":@"26",
                               @"新疆":@"27",
                               @"内蒙古":@"28",
                               @"海南":@"29",
                               @"福建":@"30",
                               @"甘肃":@"31"};
        
        params[@"kq"] = dic[kaoqu]?:@"";
        
    }
    if(wenli && ![wenli isEqualToString:@"不限"]){
        params[@"wl"] = [wenli isEqualToString:@"文科"]?@"1":@"2";
    }
    
    params[@"pc"] = pici;
    params[@"dl"] = dalei;
    params[@"zy"] = zhuanye;
    params[@"page"] = page;
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/major4"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *dataArray = responseDic[@"extraData"][@"info"];
                 
                 success(dataArray);
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];

    
}
+ (void)colleageWithZhuanYe:(NSString *)zhuanye dq:(NSString *)dq fw:(NSString *)fw success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure{

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"major"] = zhuanye;
    
    if (dq !=nil) {
        
        NSDictionary *dic = @{@"不限":@"",
                              @"北京":@"1",
                               @"天津":@"2",
                               @"上海":@"3",
                               @"重庆":@"4",
                               @"河北":@"5",
                               @"河南":@"6",
                               @"山东":@"7",
                               @"山西":@"8",
                               @"安徽":@"9",
                               @"江西":@"10",
                               @"江苏":@"11",
                               @"浙江":@"12",
                               @"湖北":@"13",
                               @"湖南":@"14",
                               @"广东":@"15",
                               @"广西":@"16",
                               @"云南":@"17",
                               @"贵州":@"18",
                               @"四川":@"19",
                               @"陕西":@"20",
                               @"青海":@"21",
                               @"宁夏":@"22",
                               @"黑龙江":@"23",
                               @"吉林":@"24",
                               @"辽宁":@"25",
                               @"西藏":@"26",
                               @"新疆":@"27",
                               @"内蒙古":@"28",
                               @"海南":@"29",
                               @"福建":@"30",
                               @"甘肃":@"31"};

        params[@"dq"] = dic[dq]?:@"";
        
    }
    if (fw !=nil) {
        params[@"fw"]= @"";
        
    }
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/major3"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *dataArray = responseDic[@"extraData"][@"info"];
                 
                 
                 success(dataArray);
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];

    
}

+ (void)zhuanyeTypeWithPici:(NSString *)pici success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];

    NSArray *piciArray =  @[@"提前批",
                            @"本科一批",
                            @"本科二批",
                            @"本科三批",
                            @"高职专科"];
    
    for (int i = 0; i < piciArray.count; i ++) {
        if ([pici isEqualToString:piciArray[i]]) {
            switch (i) {
                case 0:params[@"pc"] = @"5";break;
                case 1:params[@"pc"] = @"11";break;
                case 2:params[@"pc"] = @"12";break;
                case 3:params[@"pc"] = @"13";break;
                case 4:params[@"pc"] = @"20";break;
                default:params[@"pc"] = @"";break;
            }
            break;
            
        }
    }
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/search/dalei"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *dataArray = responseDic[@"extraData"];
                 
                 success(dataArray);
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
    
}

+ (void)zhuanyeWithPiciCode:(NSString *)piciCode success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"code"] = piciCode;
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/search/zhuanye"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *dataArray = responseDic[@"extraData"];
                 
                 success(dataArray);
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
    
}
@end
